/**
 * Test of Order function
 *
 * author: Marcin Wachulski
 *
 */
#include "OKTest.h"

class OrderTest : public testing::Test {
};

TEST_F(OrderTest, order_empty_seq) {
    FormalContext fc;

    Order(fc);
    EXPECT_EQ(0, fc.data.size());
    EXPECT_EQ(0, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}

TEST_F(OrderTest, order_one_unproc_elem) {
    FormalContext fc;
    AttributeSet *attrSet;
    ObjectSet *objSet;

    attrSet = new AttributeSet();
    attrSet->data.insert(101);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    fc.data.push_back(OAPair(objSet, attrSet));

    Order(fc);
    EXPECT_EQ(1, fc.data.size());
    EXPECT_EQ(0, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}

TEST_F(OrderTest, order_one_proc_elem) {
    FormalContext fc;
    AttributeSet *attrSet;
    ObjectSet *objSet;

    attrSet = new AttributeSet();
    attrSet->data.insert(101);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    fc.data.push_back(OAPair(objSet, attrSet));
    fc.processedNo = 1;

    Order(fc);
    EXPECT_EQ(1, fc.data.size());
    EXPECT_EQ(1, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}

TEST_F(OrderTest, order_two_elems_swap) {
    FormalContext fc;
    AttributeSet *attrSet;
    ObjectSet *objSet;

    attrSet = new AttributeSet();
    attrSet->data.insert(101);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    fc.data.push_back(OAPair(objSet, attrSet));
    
    fc.processedNo = 0;

    attrSet = new AttributeSet();
    attrSet->data.insert(102);
    objSet = new ObjectSet();
    objSet->data.insert(3);
    fc.data.push_back(OAPair(objSet, attrSet));

    Order(fc);
    EXPECT_EQ(2, fc.data.size());
    EXPECT_EQ(0, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}

TEST_F(OrderTest, order_two_elems_noswap) {
    FormalContext fc;
    AttributeSet *attrSet;
    ObjectSet *objSet;

    attrSet = new AttributeSet();
    attrSet->data.insert(101);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    fc.data.push_back(OAPair(objSet, attrSet));
    
    fc.processedNo = 1;

    attrSet = new AttributeSet();
    attrSet->data.insert(102);
    objSet = new ObjectSet();
    objSet->data.insert(2);
    fc.data.push_back(OAPair(objSet, attrSet));

    Order(fc);
    EXPECT_EQ(2, fc.data.size());
    EXPECT_EQ(1, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}

TEST_F(OrderTest, big_order) {
    FormalContext fc;
    AttributeSet *attrSet;
    ObjectSet *objSet;

    attrSet = new AttributeSet();
    attrSet->data.insert(101);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    objSet->data.insert(3);
    objSet->data.insert(4);
    fc.data.push_back(OAPair(objSet, attrSet));

    attrSet = new AttributeSet();
    attrSet->data.insert(102);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    objSet->data.insert(3);
    fc.data.push_back(OAPair(objSet, attrSet));

    attrSet = new AttributeSet();
    attrSet->data.insert(103);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    fc.data.push_back(OAPair(objSet, attrSet));
    
    attrSet = new AttributeSet();
    attrSet->data.insert(104);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    fc.data.push_back(OAPair(objSet, attrSet));

    fc.processedNo = 4;

    attrSet = new AttributeSet();
    attrSet->data.insert(105);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    fc.data.push_back(OAPair(objSet, attrSet));

    attrSet = new AttributeSet();
    attrSet->data.insert(106);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    objSet->data.insert(3);
    objSet->data.insert(4);
    fc.data.push_back(OAPair(objSet, attrSet));

    attrSet = new AttributeSet();
    attrSet->data.insert(107);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    fc.data.push_back(OAPair(objSet, attrSet));
    
    attrSet = new AttributeSet();
    attrSet->data.insert(108);
    objSet = new ObjectSet();
    objSet->data.insert(1);
    objSet->data.insert(2);
    objSet->data.insert(3);
    fc.data.push_back(OAPair(objSet, attrSet));

    Order(fc);
    EXPECT_EQ(8, fc.data.size());
    EXPECT_EQ(4, fc.processedNo);
    EXPECT_TRUE(is_sorted(fc));
}